<?php
require 'top.php';
?>



<!DOCTYPE html>
<html>
    <head lang="en">
        <meta charset="utf-8" />
        <title>商品发布</title>
        <link rel="stylesheet" type="text/css" href="css2/public.css"/>
        <link rel="stylesheet" type="text/css" href="css2/mygxin.css" />
        <style type="text/css">
            #content{
                margin:  auto;
                width: 80%;
                height: 600px;
                margin-top: 10px;
                background-color: #cae6c5;
                border-radius: 10px;
                border: 2px solid #f5f5f5;
                z-index: -10px;

            }
            .th{
                font-size: 18px;
                font-weight: bold;float: left;
                margin-left: 10px;
                /*margin-top: 20px;*/
            }
            .input{
                font-size: 14px;
                height: 30px;
                width: 450px;
                background-color: rgba(255,255,255,0.5);
            }
            .ipt{
                height: 30px;
                width: 200px;
            }
            .img{
                width: 150px;
                height: 150px;
/*                background-color: #cecac5;*/
                float: left;
                position: absolute;
                left: 38%;
            }
            .btn{
                width: 100px;
                height: 40px;
                position: absolute;
                font-size: 20px;
                left: 50%;
                bottom: 25%;
                /*background-color: blue;*/
                border-radius: 10px;
            }
        </style>
    </head>
    <body>
        <!------------------------------head------------------------------>
        
        <?php
        error_reporting(5);
error_reporting(E_ALL & ~E_NOTICE);
error_reporting(0);
header('content-type:text/html;charset=utf-8');

//身份验证
session_start();
if (!isset($_SESSION['login'])) {
    header('Refresh:3;url=login/index.php');
    echo "你还没有登陆！";
    die();
}

require 'config.php';
$email=$_SESSION['login'];
$query_email="SELECT * FROM users WHERE `uemail`='$email'";
$result_email=mysqli_query($config,$query_email);
$row_email=mysqli_fetch_array($result_email);
// echo $row_email['uemail'];
$user_email=$row_email['userid'];
// var_dump($row_email);
$gds="SELECT * FROM goods WHERE `userid`='$user_email'";
// $goods="SELECT * FROM goods ORDER BY goodsid DESC";
            $resultgoods=mysqli_query($config,$gds) or die ('SQL语句有误:'.mysql_error());
            // $row_goods=mysqli_fetch_array($resultgoods);

// $goods = "SELECT * FROM goods WHERE userid='$user_email'";
// $que_goods = mysqli_query($config,$con);
// $row_goods=mysqli_fetch_array($que_goods);
// header('content-type:text/html;charset=utf-8');
// 身份验证
// session_start();

include_once('dbtools.inc.php');
include_once('config.php');
// $link=create_connection();
// $sql="SELECT * FROM bigtype ";
// $result=mysqli_query($config,$sql);
// $row=mysqli_fetch_array($result);
// $res=execute_sql($link,'school',$sql);
// $bigtypeid=$row['bigtypeid'];
// include_once('dbtools.php');
//     $link=create_connection();
//     $sql="select * from bigtype";
// //     $result=mysqli_query($config,$sql);
//     $bigtype=db_getall($link,'school',$sql);
    // $row=mysqli_fetch_array($bigtype);
// var_dump($bigtypeid);

    // $sql2="select * from smalltype ";
    // $result2=mysqli_query($config,$sql2);
    // $row=mysqli_fetch_array($result2);
// var_dump( $row);
    // $smalltype=db_getall($link,'school',$sql2);



        ?>
        
        
        <!------------------------------Bott------------------------------>
        <div class="Bott">
            <div class="wrapper clearfix">
                <div class="zuo fl">
                    
                    <div style="height: 600px;">
                        <h4>个人中心</h4>
                        <ul>
                            <li  ><a href="manage.php">我的中心</a></li>
                            <li class="on"><a href="goods_add.php">商品发布</a></li>
                        </ul>

                        <h4>我的交易</h4>
                        <ul>
                            <li><a href="cart.php?buyerid=<?php echo $user_email;?>">我的购物车</a></li>
                            <li><a href="order_goods_ok.php?buyerid=<?php echo $user_email;?>">我的订单</a></li>
                            
                        </ul>
                        <h4>账户管理</h4>
                        <ul>
                            <li ><a href="information.php">个人信息</a></li>
                            <li><a href="xiugai_password.php">修改密码</a></li>
                        </ul>
                    </div>
                </div>
                <div class="you fl" style="height:70%;">
                    <div class="tx clearfix" >
                        <div class="fl clearfix" >
                            
                            <p class="fl"><span><?php echo $row_email['uname']?></span></p>
                        </div>
                        <div class="fr">绑定邮箱：<?php echo $row_email['uemail']?></div>
                    </div>
                
                    
                    <div class="bott">
                        <div class="clearfix" style="margin-top: -12px;margin-bottom: 100px;font-weight: bold;">

                        <h3>发布商品信息</h3>
        <div id="content">
            <form action="goods_get.php" method="post" enctype="multipart/form-data">
                <table>
                    <tr>
                        <br/>
                        <label class="th">商品名称：
                            <input class="input" type="text" name="gsn">
                        </label> 
                    </tr><br/><br/>
                    <tr>
                        <label class="th">商品类型：
                            <select name="lx" >
                                <option>二手</option>
                                <option >仅试穿</option>
                            </select>
                        </label>
                    </tr><br/><br/>
                   
                    <tr>
                        <label class="th">商品分类：

                            <select name="fl" id="selected" class="cl">
                             <?php 
                             // while ($ro=mysqli_fetch_array($result)) {
                             // var_dump($ro['bigtypeid']);
                             ?>
                             <option value="1">春秋装</option>
                             <option value="2">夏装</option>
                             <option value="3">冬装</option>
                             <option value="4">鞋子</option>
                             <option value="5">运动装备</option>
                             <option value="6">其他</option>
                                <!-- <option><?php echo $ro['bigtypename'];?></option> -->
                            <?php ?>
                            </select>
                            <select id="subclass" name="ejfl">
                                <?php 



                                // while($row_s=mysqli_fetch_array($result2)){
                                // var_dump($row_s['bigtypeid']);
                                    // while($row_s['bigtypeid']==){
                                ?>
                             <!-- <option><?php echo $row_s['smalltypename'];?></option> -->  
                            <option value="1">卫衣</option>
                            <option value="2">长袖</option>
                            <option value="3">夹克</option>
                            <option value="4">外套</option>
                            <option value="5">衬衫</option>
                            <option value="6">休闲裤</option>
                            <option value="7">牛仔裤</option>
                            <option value="8">其他</option>
                              <?php ?> 
                            </select>
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">型号码数：
                          <select name="ms" >
                                <option>M码（160-165cm）</option>
                                <option>S码（165-170cm）</option>
                                <option >L码（170-175cm）</option>
                                <option >XL码（175-180cm）</option>
                                <option >XXL码（180-185cm）</option>
                            </select>
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">详情介绍：
                          <input class="input" type="text" name="xq">
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">售卖：
                            <select name="sell" >
                                <option>在售</option>
                            </select>
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">状态：
                          <select name="zt" >
                                <option>99新</option>
                                <option>98新</option>
                                <option >95新</option>
                                <option >9成新</option>
                                <option >85新</option>
                                <option >8成新</option>
                            </select>
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">售价：
                          <input class="input ipt" type="text" name="price">
                        </label>
                    </tr>
                    <tr>
                        <label class="th">原价：
                          <input class="input ipt" type="text" name="yuanjia">
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">库存：
                            <select name="kucun" >
                                <option>1</option>
                            </select>
                        </label>
                    </tr><br/><br/>
                    <tr>
                        <label class="th">图片：
                           <input type="file" name="file" id="file" onchange="imgChange(this);"/>
                        </label><br/>
                        <div class="img"><img id="imghead" src="images/3.jpg" style="width: 100%;height: 100%;" /> 
                            <!--图片显示位置-->
                        </div>
                    </tr><br/><br/>
                </table>
                <button class="btn">确认发布</button>

    </form>
                        
                        </div>

                    </div>

                </div>
            </div>
        </div>
        
        
        
        
        
        <script src="js2/jquery-1.12.4.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="js2/public.js" type="text/javascript" charset="utf-8"></script>
        <script src="js2/user.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript">
    // 选择图片显示
    function imgChange(obj) {
//获取点击的文本框
        var file = document.getElementById("file");
        // console.log(file);
        var imgUrl = window.URL.createObjectURL(file.files[0]);
        var img = document.getElementById('imghead');
        img.setAttribute('src', imgUrl); // 修改img标签src属性值
    };


    
</script>
<script type="text/javascript">
    var onecount = 0;
    var subcat = new Array();



    var selected = $('#selected')[0];
    selected.onchange=function (){
        var subclass = $('#subclass')[0];
        var value = this.value;
        var onecount = 0;
        var subcat = new Array();
        subclass.length = 0;

        // $.ajax({
        //     type:'POST',
        //     url:'goods_get.php',
        //     data:{val:value},
        //     success:function(msg){
        //         console.log('成功',msg);
        //         // arrayc = msg;
        //         // var gclass = "{\"Class\":["+msg+"]}";

        //         // var arrayc = JSON.stringify(msg,'undifiend',1);
        //         // var gclass = JSON.parse(msg);
        //         // console.log('成功',arrayc);
        //     },
        //     error:function(msg){
        //         console.log('失败',msg);
        //     }
        // });


        <?php
        $count = 0;
        $sql="select * from smalltype";
        $result=mysqli_query($config,$sql);
        while ($rs=mysqli_fetch_array($result)) {
        ?>
        subcat[<?php echo $count; ?>] = new Array("<?php echo $rs['smalltypename']; ?>","<?php echo $rs['bigtypeid']; ?>","<?php echo $rs['smalltypeid']; ?>");
        <?php
            $count++;
            }
        ?>
        onecount = <?php echo $count; ?>;

        var optionHTML;
        

        for (var i = 0; i < onecount; i++) {
            if(subcat[i][1] == value){
                optionHTML = `<option value="${subcat[i][2]}">${subcat[i][0]}</option>`
                // subclass.options[subclass.length]=new option(subcat[i][0],subcat[i][2]);
                console.log(optionHTML);
                $('#subclass').append(optionHTML);
            }
        }
        // console.log(this.value);
    }
</script>
    </body>
</html>
